<html><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>产康预约</title>

  <#assign base=request.contextPath  />
  	<base id="basePath" href="${base}">

  	<base id="basePath" href="${base}">
  	<link rel="stylesheet" href="${base}/css/demo.css" type="text/css">
  	<link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
  	<script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
  	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
  	<script type="text/javascript" src="${base}/js/zhang.js"></script>
  	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
  	<script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>


  	<script type="text/javascript" src="${base}/js/zhang.js"></script>

  <link rel="stylesheet" href="${base}/js/layui/css/layui.css" media="all">
  <link rel="stylesheet" type="text/css" href="${base}/js/layui/css/layui.css"/>
 <style type="text/css">
  form{
    		padding: 20px;
    	}
    	.layui-btn-radius{
       			border-radius: 5px;
       		}

  </style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>产康预约</legend>
</fieldset>
<div class="demoTable"style="padding:15px;">
         <button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button" style="background-color: #0092EF;">添加产康项目</button>
	</div>
<table class="layui-hide" id="table_baby" lay-filter="user"></table>
		<script type="text/html" id="barDemo">

		     {{#  if(d.appointment ==1){ }}
             <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"  href="javascript:void(0)"  onclick="Reservable('{{d.id}}')">不可预约</a>
                      {{#  } else { }}
             <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" href="javascript:void(0)"  onclick="Reservable2('{{d.id}}')">可预约 </a>

             {{#  } }}

             <i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;
             <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del"  href="javascript:void(0)"  onclick="onDelete('{{d.id}}')"  style="font-size: 20px;" ></i>

		</script>


<script src="${base}/js/layui/layui.js" charset="utf-8"></script>
<script src="${base}/js/jquery.min.js"></script>
<script>

layui.use(['form', 'layedit', 'laydate','table'], function(){
  var form = layui.form
  ,$ = layui.jquery
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  table = layui.table;
  table.render({
    elem: '#table_baby'
    ,url: '${base}/production/selectProduction'//数据接口
    ,cols: [[
    //function()是格式化id,本应该id是long类型,现在格式化成int类型
      {field:'id',templet:function(val){
                                return val.LAY_INDEX
                             }, title: 'ID', width:60}
      ,{field:'project', title: '产康项目', align:'center'}
      ,{field:'pice', title: '价格',align:'center'}
      ,{field:'appointment',templet:function(val){
                              if(val.appointment=="1"){
                              return "可预约";
                              }else{
                              return "不可预约";
                              }
                            }, title: '状态', align:'center'}
      ,{field: 'right',align:'center', toolbar: '#barDemo', title: '操作'}
    ]]
    ,id: 'testReload'
    ,page: {
           layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
           ,theme: '#0092EF'
           ,limit:20
        }
    ,height: 500
  });
 var active = {
    	offset: function(othis){
    	  var type = othis.data('type')
    	  ,text = othis.text();
		  layer.open({
		  type: 2,
		  title: '添加产康项目',
		  shadeClose:false ,
		  area:['460px','300px'],
		  content: '${base}/production/producion_add',

		});
	}
  };
   $('#btn2').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });



//编辑弹出层
    table.on('tool(user)', function(obj){
        var layEvent = obj.event;
        if(layEvent=="edit"){
            var data = obj.data;
            //示范一个公告层
            layer.open({
                type: 2,
                title: '编辑产康项目',
                offset: 't',
                shadeClose:false ,
                area:['460px','300px'],
                content: '${base}/production/producion_edit',
                success: function (layero, index) {
                    var iframeWin = window[layero.find
                    ('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //姓名
                    iframeWin.$("#project").val(data.project)
                    //年龄
                    iframeWin.$("#pice").val(data.pice)
                    //户口所在地
                    iframeWin.$("#id").val(data.id)
                    //渲染一下form表单
                    iframeWin.layui.form.render('select')

                }
            });
        }
    });





  //实现搜索
      $('#btn1').on('click', function(){
         var whereData={};
         var sechLin=$("#sech").val();
            if(sechLin=="project"){
                whereData.project=Trim($("#demoReload").val());
            }

          //alert("查询成功,刷新表单");
           var table = layui.table;
              //表刷新方法
             table.reload('testReload', {
             url: '${base}/production/selectProduction'
             ,where: whereData
              });
        });

});


//删除
function onDelete(id){
//提示是否删除这条数据
//data里边的customerId是需要和实体类里边的id是一样的,不然是传不过来参数的
    layer.confirm('真的要删除吗?',function(index){
        $.ajax({
            type:"POST",
            url:"${base}/production/deleteProducion",
            data:{"id":id},
            sync:false,
            success:function(data){
                //alert("删除成功")
                var table = layui.table;
                //表刷新方法
                table.reload('testReload', {
                    url:'${base}/production/selectProduction'
                    ,where: {} //设定异步数据接口的额外参数
                });
                //关闭删除是否删除的提示框
                layer.close(index);
            }
        });
    });
}



//那个房间添加那个项目
function onSubmit(){
var id = $("#id").val();
var project = $("#project").val();
var price = $("#price").val();
var appointment = $("#appointment").val();
//alert("开始执行ajax")
    $.ajax({
        type:"POST",
        url:"${base}/production/insertProduction",
        data:{"id":id,"project":project,"pice":price,"appointment":appointment},
        success:function(data){

            var table = layui.table;
                         //表刷新方法
                        table.reload('testReload', {
                        url: '${base}/production/selectProduction'
                        ,where: {}, //设定异步数据接口的额外参数
                        //height: 300
                        });
                        $(".tk2").hide(200)
                    }

    });
}

//修改状态 可预约变成不可预约
function Reservable(id){

$.ajax({
        type:"POST",
        url:"${base}/production/update",
        data:{"id":id},
        async:false,
        success:function(data){

    var table = layui.table;
                         //表刷新方法
                        table.reload('testReload', {
                        url: '${base}/production/selectProduction'
                        ,where: {}, //设定异步数据接口的额外参数
                        //height: 300
                        });

             }
});
}

//修改 不可预约修改可预约
function Reservable2(id){
//alert(id)
$.ajax({
        type:"POST",
        url:"${base}/production/update2",
        data:{"id":id},
        async:false,
        success:function(data){
        layer.msg("修改成功")
    var table = layui.table;
                         //表刷新方法
                        table.reload('testReload', {
                        url: '${base}/production/selectProduction'
                        ,where: {}, //设定异步数据接口的额外参数
                        //height: 300
                        });

             }
});
}



</script>
</body>
</html>